<?php


namespace app\common\business;

use app\common\model\mysql\Demo as DemoModel;
class Demo
{
    /**
     * business 层通过getDemoDataByCateGoryId来获取数据
     * @param $categoryId
     * @param int $limit
     * @return array|array[]|\array[][]
     */
    public function getDemoDataByCateGoryId($categoryId, $limit = 10){
        $model = new DemoModel();
        $results = $model->getDemoDataByCategoryId($categoryId, $limit);
        //halt($results); 等价于 dump(); exit;
        if(empty($results)){
            return [];
        }
        $categorys = config("category");
        foreach($results as $key => $result){
            $results[$key]['categoryName'] = $categorys[$result['category_id']] ?? "其他";
            //等价于 isset($categorys[$result['category_id']]) ? $categorys[$result['category_id']] : "其他"
        }
        return $results;
    }
}
